package com.demo.aty;

import com.binioter.guideview.Guide;
import com.binioter.guideview.GuideBuilder;
import com.demo.aty.component.MutiComponent;
import com.demo.aty.provider.Listdata;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
public class ListViewDemoSlice extends AbilitySlice {

    private Component btn;
    private ComponentContainer roots;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_list_view_demo);
        initView();
        postDelay();
    }

    private void postDelay() {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                getMainTaskDispatcher().asyncDispatch(new Runnable() {
                    @Override
                    public void run() {
                        ininData();
                    }
                });
            }
        }, 200);
    }

    private void ininData() {
        GuideBuilder builder = new GuideBuilder();
        builder.setTargetView(btn)
                .setAlpha(155)
                .setHighTargetCorner(20)
                .setHighTargetPadding(10)
                .setOutsideTouchable(true);
        builder.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
            @Override
            public void onShown() {
            }

            @Override
            public void onDismiss() {
                roots.setEnabled(true);
            }
        });
        builder.addComponent(new MutiComponent());
        Guide guide = builder.createGuide();
        guide.show(this, roots, ResourceTable.Media_arrow, "查看附近的人");
    }

    private void initView() {
        btn = findComponentById(ResourceTable.Id_btn);
        roots = (ComponentContainer) findComponentById(ResourceTable.Id_roots);
    }

    private ArrayList<Listdata> getData() {
        ArrayList<Listdata> arrayList = new ArrayList<>();

        for (int i = 1; i <= 199; i++) {
            arrayList.add(new Listdata("第" + i + "行"));
        }
        return arrayList;
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
